package cn.wangdh.domain.strategy.service.rule.tree.factory;

import cn.wangdh.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import cn.wangdh.domain.strategy.model.vo.RuleTreeVO;
import cn.wangdh.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.wangdh.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import cn.wangdh.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author WDH
 * @description 规则树工厂，用来调用各个叶子节点
 * @date 2024年10月22日 21:45
 */

@Service
public class DefaultTreeFactory {

    //这里ILogicChain的三个实现类被@Component所注入，只要你用这个map，string就是他的注入名，ILogicChain就是对应的实现类
    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;


    // 当你用service注解注入对象的时候，他就会通过这个构造函数来自动装填好
    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    //开启引擎
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        DecisionTreeEngine decisionTreeEngine = new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
        return decisionTreeEngine;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        private StrategyAwardVO strategyAwardVO;
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        private Integer awardId;

        private String awardRuleValue;

    }


}
